##id int PRIMARY KEY auto_increment；

## CRUD操作
### 创建表的时候尽量加上create_time字段, 为create_time设置默认值CURRENT_TIMESTAMP
alter table week07_03 add create_time  TIMESTAMP not null  default CURRENT_TIMESTAMP;

#创建ID
ALTER table week07_03 add id int(255) PRIMARY key  auto_increment FIRST

## 单条插入数据
ALTER table week07_03 add  name VARCHAR(100)

## 查询数据
select age from week07_03

select * from week07_03 where name='王霞' and id =1

#排序
## 升序操作（ASC)
select * from week07_03 ORDER BY age asc

## 降序操作（DESC)
select * from week07_03 ORDER BY age desc

## 获取查询结果的条数(COUNT)
select  COUNT(*) from week07_03 ORDER BY age desc

##更新字段数据
update week07_03 set name='王001' where id=1

## 删除数据
delete from week07_03 where name='王001'


## 集合操作

#并集
select age from week07_03 where age is not null
union

select age from test where age is not null

## 交集
select s1.age from
(select age from week07_03 where age is not null ) as s1

JOIN

(select age from test where age is not null) as s2

ON s1.age=s2.age


## A对B的差集（left join)
select *from  //s1对s2的差集，select就可以使用s1.age
(select age from test where age is not null)as s1
left join

(select age from week07_03 where age is not null)as s2
on s1.age=s2.age

where s2.age is  null //限定s1有，s2没有的记录


##B对A 的差集(right join）
select *from
(select age from test where age is not null)as s1
right join

(select age from week07_03 where age is not null)as s2
on s1.age=s2.age

where s1.age is  null

##补集
select s1.age from
(select age from test where age is not null) as s1
left join
(select age from week07_03 where age is not null) as s2
On s1.age=s2.age
where s2.age is null
union
select s2.age from
(select age from test where age is not null )as s1
right join

(select age from week07_03 where age is not null)as s2
on s1.age=s2.age
where s1.age is null